JSTyper: Type inference for JavaScript

نویسندگان

  • Christopher Little
  • Kathryn E. Gray
  • Scott Owens
چکیده

As with all untyped languages, JavaScript programs can contain type-mismatch-style errors. These mistakes do not necessarily cause runtime errors and can lead to subtle faults in deployed web apps. Type checking key portions of JavaScript applications can identify these mistakes early. Previous efforts to augment JavaScript with a type system have led to syntax extensions and compulsory type annotations; these increase the difficulty of integrating type-checked code into a significant code base. In JSTyper, we provide a type system which supports a broad range of idiomatic JavaScript programming, including dynamic property addition and object prototyping, and does not require type annotations. We use gradual typing-style checks to integrate with untyped JavaScript. To accomplish this, we separate a program into typed and untyped portions, checking the former and using dynamic checks to provide safe interaction with the latter. This in turn provides a low-effort migration path to checked JavaScript programs. We present our type system, a proof of soundness, and a practical implementation written in JavaScript that can be run in any modern browser.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Type Safety for JavaScript

JavaScript is a client-side scripting language for the web and has become increasingly popular with the introduction of AJAX. JavaScript is a dynamic-typed language and is closer to a functional language than a procedural language. Runtime errors can occur in JavaScript due to invalid type conversions and accesses to undefined members of objects. One solution is the use of type systems to valid...

متن کامل

Type Inference for Scripting Languages

JavaScript is a powerful imperative object based language made popular by its use in web pages. It supports flexible program development by allowing dynamic addition of members to objects. Code is dynamically typed: a runtime access to a non-existing member causes an error. In this paper we first develop a formalism of JavaScript, JS0, and a static type system that will detect such type errors....

متن کامل

Type Inference for Static Compilation of JavaScript (Extended Version)

We present a type system and inference algorithm for a rich subset of JavaScript equipped with objects, structural subtyping, prototype inheritance, and first-class methods. The type system supports abstract and recursive objects, and is expressive enough to accommodate several standard benchmarks with only minor workarounds. The invariants enforced by the types enable an ahead-of-time compiler...

متن کامل

Towards Type Inference for JavaScript

Object-oriented scripting languages like JavaScript and Python are popular partly because of their dynamic features. These include the runtime modification of objects and classes through addition of fields or updating of methods. These features make static typing difficult and so usually dynamic typing is used. Consequently, errors such as access to non-existent members are not detected until r...

متن کامل

Towards JavaScript Verification with the Dijkstra State Monad

Several special-purpose systems have been proposed to analyze programs in JavaScript and other dynamically typed languages. However, none of these prior systems support automated, modular verification for both higher-order and stateful features. This paper proposes a new refinement of the state monad, the Dijkstra state monad, as a way of structuring specifications for higher-order, stateful pr...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2015